package com.chenxingnet.service;

import javax.annotation.Resource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import com.chenxingnet.dao.UserDAO;
import com.chenxingnet.dto.*;

@Service("userService")
@Transactional(rollbackFor=Exception.class)
@SuppressWarnings("all")
public class UserService{
	@Resource(name="userDAO")
	private UserDAO userDAO = null;
	
	public void test(){
		System.out.println(userDAO.findByProperty(new HashMap()));
		System.out.println("TEST SUCCESS!!!");
	}
	
	public void create(User entity){
		userDAO.insert(entity);
	}
	
	public void update(User entity){
		userDAO.update(entity);
	}
	
	public void delete(Integer uid){
		userDAO.delete(uid);
	}
	
	public User findById(Integer uid){
		return userDAO.findById(uid);
	}
	
	public List<Map> findByProperty(Map params){
		return userDAO.findByProperty(params);
	}
	
	public Long countByProperty(Map params){
		return userDAO.countByProperty(params);
	}
	
	public static void main(String[] args) {
		ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
		UserService bean = (UserService)ctx.getBean("userService");
		bean.test();
	}
	
}
